		LIST	NOCOND,NOGEN
;
;
LARGESW:	EQU	1		;ONE IF MAXI DRIVE
;
MEMSIZE:	EQU	64
MEMSTAT:	EQU	MEMSIZE-9	;2400 HEX OFFSET
BEGINADR	EQU	MEMSTAT*1024	;THIS IS THE START OF CPM
;
CBOOT		EQU	BEGINADR+01600H	;THIS IS THE COLD BOOT
;
		ORG	0
;
	;CROMEMCO 4FDC I/O ASSIGNMENTS
CSTATPORT:	EQU	00H
CDATAPORT:	EQU	01H
IMODEPORT:	EQU	02H
IMASKPORT:	EQU	03H
PARLPORT:	EQU	04H
STATPORT:	EQU	30H
TRAKPORT:	EQU	31H
SECTPORT:	EQU	32H
DATAPORT:	EQU	33H
FLAGPORT:	EQU	34H
BANKPORT:	EQU	40H
;
START:
		LD	A,01H
		OUT	BANKPORT,A
;
;
		LD	HL,BEGINADR	;START OF CP/M
		LD	DE,51*256+2	;SECTOR COUNT, FIRST SECTOR
;
;			RESTORE TO TRACK ZERO
;
		LD	A,21H+LARGESW*10H
		OUT	FLAGPORT,A
		LD	A,0FH-LARGESW*2
RST0:		OUT	STATPORT,A
RST1:		IN	A,FLAGPORT
		RRA
		JR	NC,RST1
		IN	A,STATPORT
		AND	A,98H
		JR	NZ,START
;
;			READ ONE SECTOR
;
RDI0:		LD	A,E
		OUT	SECTPORT,A
		LD	BC,8000H+DATAPORT
		LD	A,0A1H+LARGESW*10H
		OUT	FLAGPORT,A
		LD	A,88H
		OUT	STATPORT,A
RDI1:		IN	A,FLAGPORT
		RRA
		JR	C,RDI3
		INI
		JR	NZ,RDI1
RDI2:		IN	A,FLAGPORT
		RRA
		JR	NC,RDI2
;
;			CHECK STATUS AND READY FOR NEXT SECTOR AND TRACK
;
RDI3:		IN	A,STATPORT
		AND	A,9CH
		JR	NZ,START	;RETRY BOOT IF ERROR
		DEC	D
		JP	Z,CBOOT		;SEE IF ALL DONE
		INC	E
		LD	A,E		;INCREMENT SECTOR NUMBER
		CP	A,19+LARGESW*8
		JR	C,RDI0		;JUMP IF NOT END OF TRACK
		LD	E,1
		LD	A,5FH-LARGESW*2	;GO TO NEXT TRACK
		JR	RST0
;
		END
